/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jnetmonitor.models;

import java.util.Vector;
import javax.swing.table.AbstractTableModel;
import jnetmonitor.entities.SniffedPacketEntity;

/**
 *
 * @author r1nlx0
 */
public class SnifferTableModel extends AbstractTableModel {

    private String[] titles = new String[] {"Source Mac Address",
    "Destination Mac Address", 
    "Type", "Packet" 
    };
    
    private Class[] types  = new Class[] {
        String.class, 
        String.class,
        String.class,
        String.class
    };
    
    private Vector<SniffedPacketEntity> datas;
    
    public SnifferTableModel() {
        this.datas = new Vector<SniffedPacketEntity>();
        
    }
    
    public SnifferTableModel(Vector<SniffedPacketEntity> datas) {
        this.datas = datas;
    }
    
    @Override
    public int getRowCount() {
        return this.datas.size();
    }

    @Override
    public int getColumnCount() {
        return this.types.length;
        
    }
    
    public String getColumnName(int c)
    {
        return this.titles[c];
    }
    
    public Class getColumnClass(int c) {
        return this.types[c];
    }
    
    public Vector<SniffedPacketEntity> getDatas() {
        return this.datas;
        
    }
    
    public void addEntity(SniffedPacketEntity entity) {
        this.datas.add(entity);
        fireTableDataChanged();
    }
    
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex) {
            case 0:
                return this.datas.get(rowIndex).getSrc_mac();
                
            case 1:
                return this.datas.get(rowIndex).getDest_mac();
                
            case 2:
                return this.datas.get(rowIndex).getType();
                
            case 3:
                return this.datas.get(rowIndex).getPacket();
                
            
        }
        return null;
        //throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
